﻿<script type="text/javascript">
  var timeout = 0;
  var timerId = null;
  var kierunek = 'lewo';
  var pole = null;
  function startScroll(nazwaPola, lewoprawo, czas)
  {
    if(timerId != null && kierunek != lewoprawo)
      stopScroll();
    
    if(timerId != null) return;
    
    pole = document.getElementById(nazwaPola);
    if(!pole) return;
    
    timeout = czas;
    kierunek = lewoprawo;
    timerId = setInterval("scroll()", timeout);
  }
  function stopScroll()
  {
    if(timerId != null){
      clearInterval(timerId);
      timerId = null;
    }
  }
  function scroll()
  {
    if(!pole || !pole.value){
      stopScroll();
      return;
    }
    var text = pole.value;
    if(kierunek == 'lewo')
      pole.value = text.substr(1, text.length - 1) + text.substr(0,1);
    else
      pole.value = text.substr(text.length - 2,text.length - 1) +
           text.substr(0, text.length - 2);
  }
</script>